﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TuoiThoProject.DAL;

namespace TuoiThoProject.BLL
{
    public class EventBLL
    {
        EventDataContext data = new EventDataContext();

        public List<tblEvent> getEvent_All()
        {
            return (from e in data.tblEvents
                    select e).ToList();
        }

        public void AddEvent(string Description, string Url)
        {
            tblEvent e = new tblEvent();
            e.nDescription = Description;
            e.nUrl = Url;

            data.tblEvents.InsertOnSubmit(e);
            data.SubmitChanges();
        }

        public void UpdateEvent(int EventId, string Description, string Url)
        {
            tblEvent e = data.tblEvents.SingleOrDefault(e1 => e1.nEventId == EventId);
            e.nDescription = Description;
            e.nUrl = Url;

            data.SubmitChanges();
        }

        public void DeleteEvent(int EventId)
        {
            tblEvent e = data.tblEvents.SingleOrDefault(e1 => e1.nEventId == EventId);
            data.tblEvents.DeleteOnSubmit(e);
            data.SubmitChanges();
        }
    }
}